<?php
/**
 * 
 * ClientEngage: ClientEngage Visitor Voice (http://www.clientengage.com)
 * Copyright 2012, ClientEngage (http://www.clientengage.com)
 *
 * You must have purchased a valid license from CodeCanyon in order to have 
 * the permission to use this file.
 * 
 * You may only use this file according to the respective licensing terms 
 * you agreed to when purchasing this item on CodeCanyon.
 * 
 * 
 * 
 *
 * @author          ClientEngage <contact@clientengage.com>
 * @copyright       Copyright 2013, ClientEngage (http://www.clientengage.com)
 * @link            http://www.clientengage.com ClientEngage
 * @since           ClientEngage - Visitor Voice v 1.0
 * 
 */
?>

<?php
echo $this->Html->script('jquery/highlight/jquery.highlight');
echo $this->Html->scriptBlock('
$(document).ready(function(){
    $(".input_searchphrase").keyup(function(){
        if( $(this).val() != "")
        {
            $("table").unhighlight();
            $("table tbody").highlight($(this).val());

            $(this).parents(".accordion-group").find(".searchable tbody > tr").hide();
            $(this).parents(".accordion-group").find(".searchable td:contains-ci(\'" + $(this).val() + "\')").parent("tr").show();

            if($(this).parents(".accordion-group").find(".searchable td:contains-ci(\'" + $(this).val() + "\')").parent("tr").length == 0)
            {
                $(this).css("border", "1px solid #f00");
            }
            else {
                $(this).css("border", "");
            }
        }
        else
        {
            $(this).parents(".accordion-group").find(".searchable tbody > tr").show();
            $(this).css("border", "");
            $("table").unhighlight();
        }
    });
});
$.extend($.expr[":"], 
{
    "contains-ci": function(elem, i, match, array) 
	{
		return (elem.textContent || elem.innerText || $(elem).text() || "").toLowerCase().indexOf((match[3] || "").toLowerCase()) >= 0;
	}
});
');


$exclNull = array_filter($stats['values'], 'strlen');
$count = count($exclNull);
$values = array_count_values($exclNull);
arsort($values);
?>

<div class="well">
    <?php echo $this->Form->input('searchphrase', array('class' => 'input_searchphrase', 'label' => false, 'div' => false, 'placeholder' => __('Search...'))); ?>
</div>

<table class="table table-condensed table-striped searchable">
    <thead>
        <tr>
            <th class="text_frequencies-header"><?php echo __('Count (%)'); ?></th>
            <th><?php echo __('String'); ?></th>
        </tr>
    </thead>
    <tbody>
        <?php foreach ($values as $str => $c): ?>
            <tr>
                <td><?php echo $c . ' (' . round(($c / $count) * 100, 1) . '%)'; ?></td>
                <td><?php echo $str; ?></td>
            </tr>
        <?php endforeach; ?>
    </tbody>
</table>